﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace RedmineIssuesProvider
{
    #region Справочники

    public class Enumerations
    {
        public int id { get; set; }
        public string name { get; set; }

        public override string ToString()
        {
            return name;
        }
    }

    public class Project : Enumerations
    {
    }

    public class Priority : Enumerations
    {
        public int priority { get; set; }
    }

    public class User : Enumerations
    {
    }

    public class Tracker : Enumerations
    {
    }

    public class IssueStatus : Enumerations
    {
        public bool IsClosed { get; set; }
    }
    #endregion

    public class Issue
    {
        public bool Checked { get; set; }
        public int id { get; set; }
        public string subject { get; set; }
        public Tracker tracker { get; set; }
        public Project project { get; set; }
        public IssueStatus status { get; set; }
        public User author { get; set; }
        public User assigned_to { get; set; }
        public Priority priority { get; set; }
        public DateTime due_date { get; set; }

        public Issue()
        {
            Checked = false;
        }

        public bool Closed()
        {
            return status.IsClosed;
        }

        public string GetFixText()
        {
            return "fix #" + id.ToString() + ": " + subject;
        }

        public Color GetColor(bool odd)
        {
            Color issueColor = Color.Empty;

            if (this != null)
            {

                issueColor = odd ? Color.FromArgb(0xf6, 0xf7, 0xf8) : Color.FromArgb(0xff, 0xff, 0xff);

                if (status != null)
                    if (status.name == "В работе")
                    {
                        issueColor = Color.FromArgb(0xdf, 0xff, 0xdf);
                    }

                if (priority != null)
                {
                    switch (priority.priority)
                    {
                        case 5:
                        case 4:
                            issueColor = odd ? Color.FromArgb(0xff, 0xc4, 0xc4) : Color.FromArgb(0xff, 0xd4, 0xd4);
                            break;
                        case 3:
                            issueColor = odd ? Color.FromArgb(0xff, 0xee, 0xee) : Color.FromArgb(0xff, 0xf2, 0xf2);
                            break;
                        case 1:
                            issueColor = odd ? Color.FromArgb(0xea, 0xf7, 0xff) : Color.FromArgb(0xf2, 0xfa, 0xff);
                            break;
                    }
                }
            }

            return issueColor;
        }
    }

    public class IssueList : List<Issue>
    {
        public string GetCheckedFixText()
        {
            string result = "";
            foreach (Issue issue in this.FindAll(x => (x.Checked)))
            {
                result = result + issue.GetFixText() + "\n";
            }
            return result.Length == 0 ? result : result.Substring(0,result.Length-1);
        }
    }
}
